<?php
/**
 * Created by PhpStorm.
 * User: dyane
 * Date: 2018/11/14
 * Time: 14:56
 */

namespace app\admin\controller;


use think\Db;
use think\Request;

class Test extends Base
{
    /**
    分页
     */
    public function pagedata()
    {
        $param = $this->request->param();
        $where = '1 = 1';
        if(!empty($param['name'])){
            $where .= ' and api_name like "%'.$param['name'].'%"';
        }
        if(!empty($param['category'])){
            $where .= ' and cate_id = '.$param['category'];
        }
        $count = Db::name('api')->where($where)->count();
        $limit = Request::instance()->param('limit');
        $page = Request::instance()->param('page');
        $tol = ($page-1)*$limit+1;
        $list = Db::name('api')->where($where)
            ->field('id as api_id,api_name,solo_price')
            ->where('id','>=',$tol)
            ->limit($limit)
            ->select();
        //返回数据
        return ["code"=>"0","msg"=>"","count"=>$count,"data"=>$list];
    }
    /**
     * 展示页面
     * @return \think\response\View
     */
    public function index()
    {
        $cate = Db::name('api_category')->field('id,cate_name')->select();
        $this->assign('cate',$cate);
        return view();
    }
}